home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1995 / MacHack 1995.toast / Presentations / Presentations ’91 / DAL Files / DALtool 6⁄6 (System 7.x) / DalDialog.c < prev    next >
C/C++ Source or Header  |  1991-06-07  |  4KB  |  177 lines

  1. #include <string.h>
  2. #include "DalDemo.h"
  3.  
  4. extern Str255 gPassword,gUsername, gNodename;
  5.  
  6. /*** CreateSession ***/
  7. CreateSession()
  8. {
  9.     DialogPtr    logonDialog;
  10.     int dialogDone = FALSE;
  11.     int     itemHit;
  12.     int     itemType;
  13.     Rect     itemRect;
  14.     Handle    itemHandle, OKHandle;
  15.     demoPeek demoWind;
  16.     Boolean    doCreate;
  17.     
  18.     doCreate = FALSE;
  19.     logonDialog = GetNewDialog(LOGON_DIALOG,NIL,(WindowPtr)MOVE_TO_FRONT);
  20.     GetDItem(logonDialog, OK_BUTTON, &itemType, &OKHandle, &itemRect);
  21.     
  22.     ShowWindow(logonDialog);
  23.     SetPort(logonDialog);
  24.     DrawOKButton(logonDialog);
  25.     gPassword[0] = NIL;
  26.     
  27.     while (!dialogDone)
  28.     {
  29.         if (gPassword[0] != NIL)
  30.             HiliteControl(OKHandle, 0);
  31.         else
  32.             HiliteControl(OKHandle, 255);
  33.             
  34.         ModalDialog(SignonFilter,&itemHit);
  35.         switch (itemHit)
  36.         {
  37.             case OK_BUTTON:
  38.                 GetDItem(logonDialog, LOGON_NODE, &itemType, &itemHandle, &itemRect);
  39.                 GetIText(itemHandle, gNodename);
  40.                 GetDItem(logonDialog, LOGON_NAME, &itemType, &itemHandle, &itemRect);
  41.                 GetIText(itemHandle, gUsername);
  42.                 doCreate = TRUE;
  43.             case CANCEL_BUTTON:
  44.                 dialogDone = TRUE;
  45.                 HideWindow(logonDialog);
  46.                 break;
  47.         }
  48.     }
  49.     if (doCreate)
  50.     {
  51.         SetCursor(*GetCursor(watchCursor));
  52.         CreateWindow();
  53.         demoWind = (demoPeek) FrontWindow();
  54.         CtoPstr(gPassword);
  55.         DALOpenLink(demoWind,gNodename, gUsername, gPassword);
  56.         SetCursor(&arrow);
  57.     }
  58. }
  59.  
  60. /*** DrawOKButton ***/
  61. DrawOKButton(dp)
  62. DialogPtr dp;
  63. {
  64.     int        itemType;
  65.     Rect    itemRect;
  66.     Handle    item;
  67.     GrafPtr    oldPort;
  68.     
  69.     GetDItem(dp, OK_BUTTON, &itemType, &item, &itemRect);
  70.     GetPort(&oldPort);
  71.     SetPort( dp);
  72.     
  73.     PenSize(3,3);
  74.     InsetRect(&itemRect,-4,-4);
  75.     FrameRoundRect(&itemRect,16,16);
  76.     PenNormal();
  77.     
  78.     SetPort(oldPort);
  79. }
  80.  
  81.  
  82. /*** SignonFilter ***/
  83. pascal Boolean SignonFilter(dp, theEvent, itemHit)
  84. DialogPtr dp;
  85. EventRecord *theEvent;
  86. int *itemHit;
  87. {
  88.     Handle        item;
  89.     int            itemType;
  90.     Rect        itemRect;
  91.     char        theChar;
  92.     Str255        theStr;
  93.     char        frontStr[255],backStr[255];
  94.     int            selStart,selEnd;
  95.     DialogPeek    dPeek;
  96.     int            flag = FALSE;
  97.     
  98.     GetDItem( dp, LOGON_PSWD, &itemType, &item, &itemRect);
  99.     GetIText( item, theStr);
  100.     
  101.     if ((theEvent->what == keyDown) || (theEvent->what == autoKey))
  102.     {
  103.         theChar = (theEvent->message & charCodeMask);
  104.         dPeek = (DialogPeek) dp;
  105.         switch (theChar)
  106.         {
  107.             case TE_CARRIAGE_RETURN:
  108.             case TE_ENTER_KEY:
  109.                 if (theStr[0] != NIL)
  110.                 {
  111.                     *itemHit = OK_BUTTON;
  112.                     GetDItem(dp, OK_BUTTON, &itemType, &item, &itemRect);
  113.                     HiliteControl(item,1);
  114.                     return(TRUE);
  115.                 }
  116.                 else
  117.                 {
  118.                     *itemHit = LOGON_PSWD;
  119.                     return(TRUE);
  120.                 }
  121.                 break;
  122.             case TE_TAB_CHAR:
  123.             case TE_LEFT_ARROW:
  124.             case TE_RIGHT_ARROW:
  125.             case TE_UP_ARROW:
  126.             case TE_DOWN_ARROW:
  127.                 break;
  128.             case TE_BS_KEY:
  129.                 if (dPeek->editField == LOGON_PSWD - 1)
  130.                 {
  131.                     int len = 0;
  132.                     selStart = (**(dPeek->textH)).selStart;
  133.                     selEnd = (**(dPeek->textH)).selEnd;
  134.                     frontStr[0] = backStr[0] = NIL;
  135.                     if (selStart == selEnd)
  136.                     {
  137.                         if (selStart > 0)
  138.                         {
  139.                             strncpy(frontStr, (char *) gPassword, selStart-1);
  140.                             frontStr[selStart-1] = NIL;
  141.                             len = strlen((char *) gPassword) - selStart;
  142.                             strncpy(backStr, (char *)(gPassword+selStart),len);
  143.                             backStr[len] = NIL;
  144.                             strcpy((char *) gPassword,frontStr);
  145.                             strcat((char *) gPassword,backStr);
  146.                         }
  147.                     }
  148.                     else
  149.                     {
  150.                         strncpy(frontStr, (char *) gPassword, selStart);
  151.                         frontStr[selStart] = NIL;
  152.                         len = strlen((char *) gPassword) - selEnd;
  153.                         strncpy(backStr, (char *)(gPassword+selEnd),len);
  154.                         backStr[len] = NIL;
  155.                         strcpy((char *) gPassword,frontStr);
  156.                         strcat((char *) gPassword,backStr);
  157.                     }
  158.                 }
  159.                 break;    
  160.             default:
  161.                 if (dPeek->editField == LOGON_PSWD - 1)
  162.                 {
  163.                      selStart = (**(dPeek->textH)).selStart;
  164.                     selEnd = (**(dPeek->textH)).selEnd;
  165.                     backStr[0] = NIL;
  166.                     strncpy(backStr, (char *)(gPassword+selEnd),strlen((char *) gPassword) - selEnd);
  167.                     gPassword[selStart] = theChar;
  168.                     gPassword[selStart + 1] = NIL;
  169.                     strcat((char *) gPassword,backStr);
  170.                     theEvent->message = (theEvent->message & 0xffffff00) + 165;
  171.                 }
  172.                 break;
  173.         }
  174.     }
  175.     return(FALSE);
  176. }
  177.